using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cocos2d;
using CocosDenshion;

namespace CampaignWP7
{
    class GamePauseLayer : CCLayer
    {
        public override bool init()
        {
            CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.CCDeviceOrientationPortrait;//.CCDeviceOrientationLandscapeLeft;

            CCMenu pMenu;
            //////////////////////////////
            // 1. super init first
            if (!base.init())
            {
                return false;
            }

            this.m_bIsTouchEnabled = true;

            CCMenuItemImage button_Resume = CCMenuItemImage.itemFromNormalImage(
                                                "Menu/StartNormal",
                                                "Menu/StartSelect",
                                                this,
                                                new SEL_MenuHandler(menuResumeCallback));
            CCMenuItemImage button_Quit = CCMenuItemImage.itemFromNormalImage(
                                                "Menu/StartNormal",
                                                "Menu/StartSelect",
                                                this,
                                                new SEL_MenuHandler(menuQuitCallback));

            pMenu = CCMenu.menuWithItems(button_Resume, button_Quit);

            pMenu.alignItemsVerticallyWithPadding(30);
            pMenu.position = CCDirector.sharedDirector().convertToUI(new CCPoint(CCDirector.sharedDirector().getWinSize().width / 2, CCDirector.sharedDirector().getWinSize().height / 2));
            this.addChild(pMenu, 1);

            return true;
        }

        public static CCScene scene()
        {
            CCScene scene = CCScene.node();

            CCLayer layer = GamePauseLayer.node();

            scene.addChild(layer);

            return scene;
        }

        public static new CCLayer node()
        {
            GamePauseLayer ret = new GamePauseLayer();
            if (ret.init())
            {
                return ret;
            }
            else
            {
                ret = null;
            }

            return ret;
        }

        void menuResumeCallback(CCObject pSender)
        {
            CCDirector.sharedDirector().popScene();
            GameStatusManager.instance.SetStatus(GameStatus.GAMESTATUS_PLAY);
            //sound
            SimpleAudioEngine.sharedEngine().resumeBackgroundMusic();
        }

        void menuQuitCallback(CCObject pSender)
        {
            CCDirector.sharedDirector().popScene();
            CCDirector.sharedDirector().popScene();
            DynamicMgr.Instance().ClearAll();
            ResDef.RemoveAllBatchNodeChildren();
            GameStatusManager.instance.SetStatus(GameStatus.GAMESTATUS_TITLE);
            //sound
            SimpleAudioEngine.sharedEngine().stopBackgroundMusic();
            //sound effect
            if (Bullet.m_iCurPlayFireEffect != -1)
            {
                SimpleAudioEngine.sharedEngine().stopEffect((uint)Bullet.m_iCurPlayFireEffect);
                Bullet.m_iCurPlayFireEffect = -1;
            }
            if (Bullet.m_iCurPlayBalloonBombEffect != -1)
            {
                SimpleAudioEngine.sharedEngine().stopEffect((uint)Bullet.m_iCurPlayBalloonBombEffect);
                Bullet.m_iCurPlayBalloonBombEffect = -1;
            }
        }
    }
}
